<template>
	<y-popup ref='popupCountShow' round='8'>
		<view class="p-30 flex flex-column text-center">
			<text class="fs-20 text-333">{{count}}</text>
			<text class="fs-12 text-999 mt-10">支付结果查询中...</text>
		</view>
	</y-popup>
</template>

<script setup>
	import { ref } from 'vue';
	import { $http, $tool } from '@/utils';
	const popupCountShow = ref()
	const count = ref(10)
	const emit = defineEmits(['result'])
	const start = (id, type = 1) => {
		popupCountShow.value.open()
		getStatus(id, type)
	}
	defineExpose({ start })
	const getStatus = (id, type) => {
		$http.get('Order/getOrderStatus', { id: id, type: type }).then(res => {
			if (res.data.status == 1) {
				count.value = 10
				popupCountShow.value.close()
				$tool.toast('订单已支付')
				emit('result', true)
			} else {
				if (count.value > 0) {
					setTimeout(() => {
						getStatus(id,type)
						count.value--
					}, 1000)
				} else {
					count.value = 10
					$tool.toast('查询订单状态失败')
					popupCountShow.value.close()
					emit('result', false)
				}
			}
		})
	}
</script>

<style>
</style>